<div class="row-content am-cf">
    <div class="row am-cf">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
            <div class="widget am-form tpl-form-line-form am-cf">
                <div class="widget-head am-cf">
                    <div class="widget-title am-fl">账号信息</div>
                </div>
                <div class="widget-body">
                    <div class="am-u-sm-6 am-u-md-6 am-u-lg-6">
                        <div class="am-form-group">
                            <label class="am-u-sm-3 am-form-label"> 昵称 </label>
                            <div class="am-u-sm-9">
                                <div class="tpl-form-text">
                                    {$model['nickname']|default='--'}
                                    <a id="nickname" href="javascript:void(0);">修改</a>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="am-u-sm-6 am-u-md-6 am-u-lg-6">
                        <div class="am-form-group">
                            <label class="am-u-sm-3 am-form-label"> 认证状态 </label>
                            <div class="am-u-sm-9">
                                <div class="tpl-form-text">
                                    未认证 <button class="but-primary">认证</button>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="am-u-sm-6 am-u-md-6 am-u-lg-6">
                        <div class="am-form-group">
                            <label class="am-u-sm-3 am-form-label"> 编号 </label>
                            <div class="am-u-sm-9">
                                <div class="tpl-form-text">
                                    {$model['user_id']}
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="am-u-sm-6 am-u-md-6 am-u-lg-6">
                        <div class="am-form-group">
                            <label class="am-u-sm-3 am-form-label"> 注册时间 </label>
                            <div class="am-u-sm-9">
                                <div class="tpl-form-text">
                                    {$model['create_time']}
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="row am-cf">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
            <div class="widget am-form tpl-form-line-form am-cf">
                <div class="widget-head am-cf">
                    <div class="widget-title am-fl">登录方式</div>
                </div>
                <div class="widget-body">
                    <div class="am-u-sm-3 am-u-md-3 am-u-lg-3">
                        <div class="am-form-group">
                            <label class="am-u-sm-3 am-form-label"> 账号 </label>
                            <div class="am-u-sm-9">
                                <div class="tpl-form-text">
                                    {$model['user_name']} <a href="{:url('setting/renew')}">修改密码</a>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="am-u-sm-3 am-u-md-3 am-u-lg-3 am-u-end">
                        {if $login['wechat']==1}
                        <div class="am-form-group">
                            <label class="am-u-sm-3 am-form-label"> 微信 </label>
                            <div class="am-u-sm-9">
                                <div class="tpl-form-text">
                                    {if empty($model['open_id'])}
                                    未关联 
                                    <button id="wechat-bind" class="but-primary">绑定</button>
                                    {else /}
                                    {$model['open_id']}
                                    {/if}
                                </div>
                            </div>
                        </div>
                        {/if}
                    </div>
                    <div class="am-u-sm-3 am-u-md-3 am-u-lg-3 am-u-end">
                        {if $login['phone']==1}
                        <div class="am-form-group">
                            <label class="am-u-sm-3 am-form-label"> 手机 </label>
                            <div class="am-u-sm-9">
                                <div class="tpl-form-text">
                                    {if empty($model['phone'])}
                                    未关联 
                                    <button id="phone-bind" class="but-primary">绑定</button>
                                    {else /}
                                    {$model['phone']}
                                    {/if}
                                </div>
                            </div>
                        </div>
                        {/if}
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="setting/tpl/phone" /}
{include file="setting/tpl/wechat" /}
{include file="setting/tpl/nickname" /}
<script>
    $(function () {
        $('#nickname').on('click', function () {
            $.get("{:url('user/edit')}", function (result) {
				if(result.code == 0){
				    $.show_error(result.msg);
				    return false;
				}
                $.showAction({
                    title: '修改昵称', 
                    area: '400px', 
                    content: template('tpl-nickname',result.data), 
                    uCheck: true, 
                    success: function ($content) {
                        $('#my-form').formPost({
                            url: "{:url('user/edit')}"
                        });
                    }, 
                    btn2: function ($content) {
                        return true;
                    }
    
                });
            });
        });
        $('#phone-bind').on('click', function () {
            $.showAction({
                title: '绑定手机号', 
                area: '400px', 
                content: template('tpl-phone-bind',{}), 
                uCheck: true, 
                success: function ($content) {
                    var captcha = document.getElementById('captcha'),
                    tel = document.getElementById('tel'),
                    telReg = /^1[3456789]\d{9}$/,
                    num = 120;
                    captcha.onclick = function(){
                        if(telReg.test(tel.value)){
                            captcha.disabled = true;
                            //请求验证码
                            $.post("/index/passport/sendsms",{
                                phone: tel.value
                            },function(res){
                                if(res.code == 1){
                                    settime(captcha);
                                }else{
                                    captcha.disabled = false;
                                    $.show_error(res.msg);
                                }
                            });
                        }else{
                            $.show_error('手机号码不正确');
                        }
                    };
                    function settime(el){
                        if(num == 0){
                            el.disabled = false;
                            el.innerHTML = "获取验证码";
                            num=120;
                            return true;
                        }else{
                            el.innerHTML = num+"s后重新获取";
                            num--;
                        }
                        setTimeout(function(){
                            settime(el);
                        },1000);
                    }
                    $('#my-form').formPost({
                        url: "{:url('user/phoneBind')}"
                    });
                }, 
                btn2: function ($content) {
                    return true;
                }

            });
        });
        $('#wechat-bind').on('click', function () {
            $.get("{:url('user/qrcodeCreate')}", function (result) {
				if(result.code == 0){
				    $.show_error(result.msg);
				    return false;
				}
                $.showAction({
                    title: '扫码关注公众号', 
                    area: '400px', 
                    content: template('tpl-wechat-bind', result.data), 
                    uCheck: true, 
                    btn: ['取消'],
                    success: function ($content) {
                        //关注公众号登录
                        var interval = setInterval(function(){
                            $.post("/index/passport/checklogin",{
                                ticket:result.data.ticket
                            },function(res){
                                if(res.code == 1){
                                    $.post("/user/user/wechatBind",{
                                        data:res.data
                                    },function(rs){
                                        if(rs.code == 1){
                                            window.location.reload();
                                            return true;
                                        }else{
                                            $.show_error(rs.msg);
				                            return false;
                                        }
                                    });
                                }
                            });
                        },3000);
                    }, 
                    btn2: function ($content) {
                        return true;
                    }
                });
            });
        });
    });
</script>
